<template>
	<div class="page">
		<!-- <van-notice-bar wrapable :scrollable="false" text="注：在录入客户信息前，请获取客户的同意" /> -->
		<div class="form-data">
			<div class="form">
				<div class="title">{{$t('language.text2')}}</div>
				<van-field v-model="title" :placeholder="$t('language.text2')" />
			</div>
			<!-- <div class="form">
				<div class="title">{{$t('language.text3')}}</div>
				<van-field v-model.number="room_num" :placeholder="$t('language.text4')" />
			</div>
			<div class="form">
				<div class="title">{{$t('language.text5')}}</div>
				<van-field v-model.number="income" :placeholder="$t('language.text6')" />
			</div> -->
			<div class="form">
				<div class="title">{{$t('language.text7')}}</div>
				<van-field v-model="agreement_price_code" :placeholder="$t('language.text8')" />
			</div>
			<div class="form">
				<div class="title">{{$t('language.text54')}}</div>
				<van-field v-model="price_code" :placeholder="$t('language.text55')" />
			</div>
			<div class="add-btn" @click="tapAddLnr">
				{{$t('language.text9')}}
			</div>
		</div>
	</div>
</template>
<script>
	import {
		addLnr,
		beLnrCreate
	} from '@/api/user';
	import {
		Toast
	} from "vant";

	let timer = null
	export default {
		name: 'AddInr',
		data: function() {
			return {
				locale: 'zh',
				type: 2,
				title: '',
				room_num: '',
				income: '',
				price_code: '',
				agreement_price_code: '',
				notTap: false
			};
		},
		created() {
			const userinfo = localStorage.getItem("userinfo")
			const {
				type
			} = JSON.parse(userinfo)
			this.type = type
		},
		mounted() {},
		methods: {
			tapAddLnr() {
				const t = this

				let data = {
					title: t.title,
					title_alias: t.title,
					// room_num: t.room_num,
					// income: t.income,
					// be_room_num: t.room_num,
					// be_income: t.be_income,
					price_code: t.price_code,
					agreement_price_code: t.agreement_price_code
				}
				if (t.notTap) return
				if (data.title == '') return Toast(t.$i18n.tc('language.text2'));
				if (data.title_alias == '') return Toast(t.$i18n.tc('language.text2'));
				// if(data.room_num == '') return Toast(t.$i18n.tc('language.text4'));
				// if(data.income == '') return Toast(t.$i18n.tc('language.text6'));
				if (data.price_code == '') return Toast(t.$i18n.tc('language.text8'));
				if (data.agreement_price_code == '') return Toast(t.$i18n.tc('language.text55'));

				t.notTap = true
				timer = setTimeout(() => {
					t.notTap = false
					clearTimeout(timer)
					timer = null
				}, 1000)

				if (t.type !== 4) {
					addLnr(data).then((res) => {
						if (res.status_code != 200) {
							Toast(res.message)
						} else {
							Toast({
								duration: 2000,
								forbidClick: true,
								message: t.$i18n.tc('language.text67'),
							})
							setTimeout(() => {
								t.$router.back()
							}, 2000)
						}
					}).catch((err) => {
						console.log(err)
					})
					return
				}
				beLnrCreate(data).then((res) => {
					if (res.status_code != 200) {
						Toast(res.message)
					} else {
						Toast({
							duration: 2000,
							forbidClick: true,
							message: t.$i18n.tc('language.text67'),
						})
						setTimeout(() => {
							t.$router.back()
						}, 2000)
					}
				}).catch((err) => {
					console.log(err)
				})
			},
			changeLanguage() {
				if (this.$i18n.locale == 'zh') {
					this.$i18n.locale = 'en';
					this.$cookies.set('locale', 'en')
				} else {
					this.$i18n.locale = 'zh';
					this.$cookies.set('locale', 'zh')
				}
			}
		}
	};
</script>
<style type="text/css" lang="scss" scoped>
	.page {
		background-color: #fff;
	}

	.van-notice-bar--wrapable {
		font-size: 24px;
		padding: 20px 30px;
		color: #e8542c;
		background-color: #fbf4f3;
	}

	.form-data {
		padding: 0 30px;
	}

	.form {
		margin-top: 50px;
		padding-bottom: 30px;
		border-bottom: 1px solid #eee;

		.title {
			font-size: 30px;
			color: #333333;
			margin-bottom: 36px;
		}

		.van-cell {
			padding: 0;
		}

		.van-field__control {
			font-size: 24px;
		}
	}

	.add-btn {
		width: 100%;
		padding: 21px 0;
		margin-top: 50px;
		color: #fff;
		font-size: 28px;
		border-radius: 10px;
		text-align: center;
		background-color: #e8542c;
	}
</style>